<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:template match="HeaderInfo">
using System;
using System.Data;
using MySql.Data.MySqlClient;
	
namespace <xsl:value-of select="ProjectName"/>.DataObject 
{
	[Serializable]
	public abstract class <xsl:value-of select="ProjectName"/>DataObject 
	{
		public Int64 ObjectID { get; set; }
		public DateTime CreatedDate { get; set; }
		public DateTime ModifiedDate { get; set; }
		
		public bool dirty;
		
		protected bool insertOrUpdate ( IDbConnection sqlCon )
		{
			if( ObjectID == 0 ) 
			{
				return insert ( sqlCon );
			} 
			else 
			{
				return update ( sqlCon );
			}
		}
		
		
		public virtual bool Save () 
		{
			bool ret;
			using ( IDbConnection sqlCon = new MySqlConnection ( GetDB ( ) ) ) 
			{
				sqlCon.Open ();
				ret = insertOrUpdate ( sqlCon );
				sqlCon.Close ();
			}
			return ret;
		}
		
		
		protected abstract bool insert( IDbConnection sqlCon );
		protected abstract bool update( IDbConnection sqlCon );
		
		public static string GetDB() {
			if(System.Configuration.ConfigurationSettings.AppSettings["MYDB"]==null) {
				return "<xsl:value-of select="DBConnection"/>";
			}
			return System.Configuration.ConfigurationSettings.AppSettings["MYDB"];
		}
		
	
	}



}
	
	
	</xsl:template>
</xsl:stylesheet>
